/**
 * Clase Leer
 *
 * @author David Candia Martin
 * @version 1.0 - 11/12/13
 */
package clases;

import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;

public class Leer {

	private static final String RUTA = "ficheros/alumnos.bin";

	/**
	 * Lee los objetos almacenados en un archivo binario.
	 */
	public ArrayList<Alumno>  leer_objeto() {
		ArrayList<Alumno> lista = new ArrayList<Alumno>();
		FileInputStream f_in = null;
		ObjectInputStream o_in = null;
		try {
			Alumno al;

			f_in = new FileInputStream(RUTA);
			o_in = new ObjectInputStream(f_in);

		
			try {

				while (true) {
					al = (Alumno) o_in.readObject();
					lista.add(al);
				
				}
			}

			catch (EOFException e) {
				
			}

		} catch (FileNotFoundException ex) {
			System.err.println("FileNotFoundException");
		} catch (IOException ex) {
			System.err.println("IOException");
		} catch (ClassNotFoundException ex) {
			System.err.println("ClassNotFoundException");
		} finally {
			try {
				o_in.close();
			} catch (IOException ex) {
				System.err.println("IOException");
			}
		}

		return lista;
	}

}
